import store from 'store';
import $helper from '@/services/helper.service';

const env = process.env.NODE_ENV
class StorageService {
  keys = {
    USER_TICKET: $helper.md5(`${env}USER_TICKET`),
    PLAY_LIST: $helper.md5(`${env}PLAY_LIST`),
    VOLUME: $helper.md5(`${env}VOLUME`),
    searchHistory: $helper.md5(`${env}searchHistory`),
    plat: $helper.md5(`${env}plat`)
  };

  constructor() {
    // this.fixOldVersionPlayListData()
  }

  getUserTicket() {
    const key = this.keys.USER_TICKET;
    // let mockTicket = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjk4NDA3MDQ4LCJleHAiOjE2OTkwMTE4NDh9.1pJWToEyJdCVLRyUwYG73qBXFyYYfyovQL2NpZOeskk"
    let mockTicket = ""
    let storedToken = store.get(key) || mockTicket;
    

    return storedToken
  }

  setUserTicket(token) {
    store.set(this.keys.USER_TICKET, token);
    
    // let d: string = $helper.encrypt({
    //   t: token,
    //   e: Date.now() + environment.tokenExpire,
    // });
    // store.set(this.keys.USER_TICKET, d);
  }
  removeUserToken() {
    store.remove(this.keys.USER_TICKET);
  }

  remove(key) {
    store.remove(key);
  }
}

const $storage = new StorageService();

window.$storage = $storage

export default $storage;
